<?php
require_once(dirname(__FILE__)."/Utility.php");
require_once(dirname(__FILE__)."/MockDataHelper.php"); 


foreach (  $_GET  as $key => $value ){
	if (! isset ( ${$key} ))
		${$key} = $value;
}

foreach (  $_POST  as $key => $value ){
	if (! isset ( ${$key} ))
		${$key} = $value;
}
	if (! isset($action)) $action = "";
	

//start to setup the amazon helper configuration according to parmaeters passed input via http	
	$config = json_decode($config,true);

//pharse the parameters for this api call
	if (isset($parms) and $parms<>'' and $parms <>null)
		$parms = json_decode($parms,true);
	else
		$parms = array();

//initilize the result
	$results = "Ready to do action ".$action;
	
/******************     refresh order  start      **********************/
	/**
	 +---------------------------------------------------------------------------------------------
	 * GetOrder list according to the from Date time and target statuses
	 +---------------------------------------------------------------------------------------------
	 * @Parameters
	 +---------------------------------------------------------------------------------------------
	 * @fromDateTime		UTC format date time, orders modified after this time will be retrieved
	 * 						
	 * @status 				Statuses shall be retrieved. e.g. Unshipped / Unshipped,Shipped
	 * Valid Statuses are below:
	 * Pending 订单已下达，但付款
	 *  		尚未经过授权。未准
	 *  		备好进行发货。
	 * Unshipped 付款已经过授权，订
	 *  		单已准备好进行发
	 *  		货，但订单中商品尚
	 *  		未发运。
	 * PartiallyShipped 订单中的一个或多个
	 *  		（但并非全部）商品
	 *  		已经发货。
	 * Shipped 订单中的所有商品均
	 *  		已发货。
	 * InvoiceUnconfirmed 订单内所有的商品都
	 *  		已发货，但是卖家还
	 *  		没有向亚马逊确认已
	 *  		经向买家寄出发票。
	 *  		请注意：此参数仅适
	 *  		用于中国地区。
	 * Canceled 订单已取消。
	 * Unfulfillable 订单无法进行配送。
	 *  		该状态仅适用于通过
	 *  		亚马逊零售网站之外
	 *  		的渠道下达但由亚马
	 *  		逊进行配送的订单。
	 *  
	 *  请注意： 在此版本的“订单 API”部分中，必须
	 *  	    同时使用未发货和已部分发货。仅使用
	 *		    其中一个状态值，则会返回错误。
	 +---------------------------------------------------------------------------------------------
	 * log			name	date					note
	 * @author		yzq		2014/04/17				初始化
	 +---------------------------------------------------------------------------------------------
	 **/
if (strtolower($action) == strtolower("GetOrder")) {
	$mockHelper=new MockDataHelper();
	echo $mockHelper->getOrderListMockData();
	return;
}


if (strtolower($action) == strtolower("GetOrderItem")) {
	$mockHelper=new MockDataHelper();
	echo $mockHelper->getOrderItemsMockData();
	return;	
}

/******************     refresh order  end      **********************/


/******************     change order start      **********************/
if (strtolower($action)  == strtolower("ShipAmazonOrder")) {
//	$results = AmazonService::ShipAmazonOrder($parms['order_id'] ,$parms['items'] , $parms['freight'], $parms['delivery_no'], $parms['ship_date']);
	$mockHelper=new MockDataHelper();
	echo $mockHelper->shipOrder();
	return;
	
}


if (strtolower($action)  == strtolower("RefundAmazonOrderItem")) {
	//$results = AmazonService::RefundAmazonOrderProduct($parms);
}

if (strtolower($action)  == strtolower("CancelEntireAmazonOrder")) {
	//$results = AmazonService::CancelEntireAmazonOrder($parms);
}
/******************     change order status end      **********************/

/*----------------------------------------------------------------------------*/
/******************          Report Related Starts       **********************/
/*----------------------------------------------------------------------------*/
/**
 +---------------------------------------------------------------------------------------------
 * (Logic Briefing)Request an Amazon report for product list
 +---------------------------------------------------------------------------------------------
 * @steps 
 +---------------------------------------------------------------------------------------------
 * @Step 1				RequestAmazonReport: 
 * 						Can request multiple reports for the merchant id.
 * 						Then amazon returns a request id 
 * @Step 2 				GetAmazonReportIds:
 * 						Check the report ids generated by this request
 * 						Amazon returns the reports(ids) 
 * @Step 3 				GetStoreAllProduct(report_id): 
 * 						Get the report for this report id and parse its content to 
 * 						generate the array of all products 
 +---------------------------------------------------------------------------------------------
 * log			name	date					note
 * @author		yzq		2014/04/17				初始化
 +---------------------------------------------------------------------------------------------
 **/
/**
 +---------------------------------------------------------------------------------------------
 * Get all product list by parsing amazon report result. AmazonService::GetStoreAllProduct
 +---------------------------------------------------------------------------------------------
 * @param
 * 						report_id
 +---------------------------------------------------------------------------------------------
 * @return 				Array
        				(
    				        [success] => 1
               				[message] => 
               				[products] => Array
       				            (
                       				[0] => Array
                           				(
                               				[sku] => 1520-10.8^^^5200
                               				[asin] => B00IHVE550
                               				[price] => 26.49
                               				[quantity] => 60
                           				)

                       				[1] => Array
                           				(
                               				[sku] => 1520-11.1^^^4800
                               				[asin] => B00IHVE6H2
                               				[price] => 26.49
                               				[quantity] => 5
                           				)
                   				)
           				)
 +---------------------------------------------------------------------------------------------
 **/
if (strtolower($action) == strtolower("GetStoreAllProductByReport")) {
	//retrieve the result of a particular report and convert to store all product list
	//$results = AmazonService::GetStoreAllProduct($parms['report_id']);
}



/**
 +---------------------------------------------------------------------------------------------
 * Request an Amazon report. AmazonService::RequestAmazonReport
 +---------------------------------------------------------------------------------------------
 * @param				
 * 						report_type
 * 						start_date
 * 						end_date
 +---------------------------------------------------------------------------------------------
 * @return 				Array
 *       				(
 *           				[success] => 1
 *           				[message] => 
 *           				[ReportRequestId] => 8432781584
 *          				[ReportType] => _GET_FLAT_FILE_OPEN_LISTINGS_DATA_            			
 *          				[SubmittedDate] => 2014-04-17 03:53:30
 * 				            [ReportProcessingStatus] => _SUBMITTED_
 *      				)
 +---------------------------------------------------------------------------------------------
 **/
if (strtolower($action) == strtolower("RequestAmazonReport")) {
	//retrieve the result of a particular report and convert to store all product list
	//$results = AmazonService::RequestAmazonReport( $parms['report_type'] , $parms['start_date'] , $parms['end_date']);
	
}





/**
 +---------------------------------------------------------------------------------------------
 * Get the report ids from a request. AmazonService::GetAmazonReportIds
 +---------------------------------------------------------------------------------------------
 * @param
 * 						request_id
 +---------------------------------------------------------------------------------------------
 * @return 				  Array
 *				 		  (
 * 		        			 [success] => 1
 *				 		     [message] => 
 * 		        			 [report] => Array
 *		 		                  (
 *       				              [0] => Array
 * 	       				                  (
 * 	                       				      [ReportId] => 34292388144
 *		 		                              [ReportType] => _GET_FLAT_FILE_OPEN_LISTINGS_DATA_
 * 	       				                      [AvailableDate] => 2014-04-17 06:17:11
 *		 		                          )	  
 * 	       				          )
 *		 		          )                
 +---------------------------------------------------------------------------------------------
 * @desc				if the report array has no element, the report is not ready,Load later	 		          
 **/
if (strtolower($action) == strtolower("GetAmazonReportIds")) {
	//retrieve the reports id for the report request
//	$results = AmazonService::GetAmazonReportIds( $parms['request_id'] );
}

/******************     post inventory end      **********************/

/*****************      products start *****************/
if ($action=="get_matching_products"){
 
}

/*****************      products end *****************/

/*****************      reports start *****************/
if ($action=="GetAmazonSubmitFeedResult"){
	$mockHelper=new MockDataHelper();
	echo $mockHelper->getSubmitFeedResult();
	return;
}

if ($action=="test_report"){
 
}

/*****************      reports end *****************/

/*****************      fba start *****************/
if ($action=="retrieve_amz_fba_prod_inventory"){
}
/*****************      fba end *****************/
if ($action == "")
	echo " no api action is required ! <br>";
else
	echo json_encode($results);
 

 

?>

